package com.gwcloud.leetcode.offers;

import java.util.HashMap;

/** 
* @ClassName   : Leetcode0480 
* @author      : ganwei 
* @date        : 2020年6月6日 
* @Description : TODO 
*/
public class Leetcode0480 {
	/**
	 * -解题思路,滑动窗口
	 */
    public int lengthOfLongestSubstring(String s) {
        //存储字符出现次数
    	HashMap<Character, Integer> cnums = new HashMap<Character, Integer>();
    	int left = 0, right = 0;
    	int res = 0;
    	while(right < s.length()) {
    		char c = s.charAt(right);
    		right++;
    		
    		cnums.put(c, cnums.getOrDefault(c, 0)+1);
    		while(cnums.get(c) > 1) {
    			char d = s.charAt(left);
    			left++;
    			
    			cnums.put(d, cnums.get(d)-1);
    		}
    		res = Math.max(res, right-left);
    		
    	}
    	
        
    	return res;
    	
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	
    }
}
